package cn.openread.starter.utils.sms;

import jodd.http.HttpRequest;
import jodd.http.HttpResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * http://www.montnets.com/
 * <p>
 * 梦网科技-sms服务
 *
 * @author Simon
 */
@Slf4j
public class MengWangSmsServiceImpl implements SmsService {

    @Override
    public Boolean singleSend(SmsSendModel smsSendModel) {
        //step 1.参数基本校验
        smsSendModel.validate();
        MengWangSmsModel mengWangSmsModel = (MengWangSmsModel) smsSendModel;

        //step 2.处理发送
        HttpResponse httpResponse = HttpRequest.post(String.format("%s/sms/v2/std/single_send", mengWangSmsModel.getDomain()))
                .contentTypeJson()
                .body(mengWangSmsModel.toSendString())
                .send();

        //step 3.返回结果
        String body = httpResponse.body();
        log.debug("发送短信,服务商接口响应=>{}", body);
        return StringUtils.contains(body, "\"result\":0,");
    }
}
